import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SelCount {
    public static void main(String[] args) {
        String sql = "select fromcity as '城市', count(*) as'人数' from s_student group by fromcity";
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DBUtil.getConnection();
            ps = con.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                String city = rs.getString("城市");
                if (city == null) {
                    city = "未确定";
                }
                int count = rs.getInt("人数");
                System.out.println("城市：" + city + ",人数：" + count);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            DBUtil.close(rs, ps, con);
        }
    }
}

